﻿using ZYCommon;
using System;
using System.Drawing;
using Windows32;

namespace TextEditor
{
    

    public class ImageDistanceAction : ImageEditAction
    {
        public Point DrawFix = Point.Empty;
        public Point p1 = Point.Empty;
        public Point p2 = Point.Empty;
        public double XRate = 1.0;
        public double YRate = 1.0;

        public void Clear()
        {
            this.p1 = Point.Empty;
            this.p2 = Point.Empty;
        }

        public override bool Execute(Graphics g, Rectangle ClipRect)
        {
            int hDC = g.GetHdc().ToInt32();
            int drawMode = Gdi32.GetROP2(hDC);
            int hObject = Gdi32.CreatePen(0, 1, 0xffffff);
            int num4 = Gdi32.SelectObject(hDC, hObject);
            Gdi32.SetROP2(hDC, 7);
            Gdi32.MoveToEx(hDC, this.p1.X + this.DrawFix.X, this.p1.Y + this.DrawFix.Y, 0);
            Gdi32.LineTo(hDC, this.p2.X + this.DrawFix.X, this.p2.Y + this.DrawFix.Y);
            if (this.Distance > 1.0)
            {
                double distance = this.Distance;
                int num6 = this.p2.X - this.p1.X;
                int num7 = this.p2.Y - this.p1.Y;
                int num8 = (int) (((double) (num7 * 20)) / (distance * this.XRate));
                int num9 = (int) (((double) (num6 * 20)) / (distance * this.YRate));
                for (double i = 0.0; i <= distance; i++)
                {
                    double num11 = (this.DrawFix.X + this.p1.X) + ((i * num6) / distance);
                    double num12 = (this.DrawFix.Y + this.p1.Y) + ((i * num7) / distance);
                    Gdi32.MoveToEx(hDC, (int) num11, (int) num12, 0);
                    Gdi32.LineTo(hDC, ((int) num11) + num8, ((int) num12) - num9);
                }
            }
            Gdi32.SelectObject(hDC, num4);
            Gdi32.DeleteObject(hObject);
            Gdi32.SetROP2(hDC, drawMode);
            g.ReleaseHdc(new IntPtr(hDC));
            return true;
        }

        public override string ActionName
        {
            get
            {
                return "distance";
            }
        }

        public override Rectangle Bounds
        {
            get
            {
                return RectangleObject.GetRectangle(this.p1, this.p2);
            }
            set
            {
            }
        }

        public double Distance
        {
            get
            {
                if ((this.XRate * this.YRate) != 0.0)
                {
                    double num = ((double) (this.p1.X - this.p2.X)) / this.XRate;
                    double num2 = ((double) (this.p1.Y - this.p2.Y)) / this.YRate;
                    return Math.Sqrt((num * num) + (num2 * num2));
                }
                return 0.0;
            }
        }
    }
}

